<template>
  <div style="position: relative">
    <div style="position: absolute;top:200px;left:300px">
      <el-cascader
          :options="options"
          :props="props"
          @change="resource"
          placeholder="请选择资源信息"
          clearable
      ></el-cascader>
    </div>
    <div style="position: absolute;top:200px;left: 900px">
      <el-select v-model="value" placeholder="请选择用户" @change="user">
        <el-option
            v-for="item in options1"
            :key="item.value"
            :label="item.label"
            :value="item.value"
        >
        </el-option>
      </el-select>
    </div>
    <div style="position: absolute;top: 100px;right: 200px">
      <button @click="post_resource" style="color: white;background-color: #2f54eb;width: 100px;height: 35px;border: none;">确定</button>
    </div>
  </div>
</template>

<script>
import maxios from "@/http/axios";

export default {
name: "add_resource",
  data(){
    return{
      props: { multiple: true },
      options:[],
      options1: [],
      value: '',
      form:{'user_id':'','list':''}
    }
  },
  methods:{
    get_resource(){
      maxios('user/resource','get').then(res=>{
        if(res.code==200){
          this.options = res.matter
          this.options1 = res.matter1
          console.log(res.matter1)
        }
      })
    },
    resource(val){
      let list = []
      for(let i in val){
        list.push(val[i][0])
        list.push(val[i][1])
      }
      this.form.list = list
    },
    user(value){
      this.form.user_id = value
    },
    post_resource(){
      maxios('/user/resource','post',this.form).then(res=>{
        if(res.code==200){
          this.$toast.success('添加成功')
        }
      })
    }
  },
  mounted() {
    this.get_resource()
  },

}
</script>

<style scoped>
.zd{
  width: 500px;
}
</style>